package com.dragon.shop_user.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.dragon.shop_common.utils.AjaxResult;
import com.dragon.shop_user.domain.param.GetOrderNoParam;
import com.dragon.shop_user.domain.vo.GetOrderNoVo;
import com.dragon.shop_user.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping("/getOrderNo")
    public AjaxResult<String> getOrderNo() {
        return userService.getOrderNo();
    }

    @GetMapping("/getOrderNo2")
    public AjaxResult<GetOrderNoVo> getOrderNo2(String userId) {
        return userService.getOrderNo2(userId);
    }

    @GetMapping("/getOrderNo3")
    public AjaxResult<GetOrderNoVo> getOrderNo3(GetOrderNoParam getOrderNoParam) {
        return userService.getOrderNo3(getOrderNoParam);
    }

    @PostMapping("/getOrderNo4")
    public AjaxResult<GetOrderNoVo> getOrderNo4(GetOrderNoParam getOrderNoParam) {
        return userService.getOrderNo4(getOrderNoParam);
    }

    @PostMapping("/getOrderNo5")
    public AjaxResult<GetOrderNoVo> getOrderNo5(@RequestBody GetOrderNoParam getOrderNoParam) {
        return userService.getOrderNo5(getOrderNoParam);
    }

    @GetMapping("/sentinelB")
    @SentinelResource(value = "userSentinelBResource", blockHandler = "getSentinelBBlockHandler", blockHandlerClass = UserController.class)
    public String sentinelB(){
        return "我是关联接口";
    }

    /**
     * 限流后续操作方法
     * 返回类型与原方法一致，参数类型需要和原方法相匹配，并在最后加上BlockException类型的参数
     */
    public static String getSentinelBBlockHandler(BlockException ex) {
        String msg = "不好意思，前方拥挤，请您稍后再试";
        return msg;
    }

}
